home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
8614
/
8614.xpi
/
modules
/
utils
/
WindowUtils.jsm
< prev
Wrap
Text File
|
2010-02-10
|
4KB
|
120 lines
// DO NOT import this into the global namespace, but instead
// import it into your own namespace wrapper
var EXPORTED_SYMBOLS = ["WindowUtils"];
Components.utils.import("resource://glydo/utils/prototype_xul_1_6_0_3_modified.jsm");
Components.utils.import("resource://glydo/utils/Utils.jsm");
Components.utils.import("resource://glydo/utils/Prefs.jsm");
var WindowUtils = {
openDialog: function(parentWindow, url, windowName, features)
{
var array = Components.classes["@mozilla.org/array;1"]
.createInstance(Components.interfaces.nsIMutableArray);
for (var i=4; i<arguments.length; i++)
{
var variant = Components.classes["@mozilla.org/variant;1"]
.createInstance(Components.interfaces.nsIWritableVariant);
variant.setFromVariant(arguments[i]);
array.appendElement(variant, false);
}
var watcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
return watcher.openWindow(parentWindow, url, windowName, features, array);
},
newBrowserWindow: function(parent,urls) {
WindowUtils.openDialog(parent, "chrome://browser/content/browser.xul",
"_blank", "chrome,dialog=no,all", urls);
},
getCurrentBrowserWindow: function(hint) {
if (hint && hint.getBrowser && hint.getBrowser()) {
return hint;
}
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
if (win && win.toolbar.visible) {
return win;
}
// else
var enumerator = wm.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements()) {
win = enumerator.getNext();
if (win.toolbar.visible) {
return win;
}
}
return null;
},
goToURL: function(parent, url, openMode) {
openMode = openMode ? openMode
: Prefs.recommendations_open_mode;
// If URL is a mailto url, open it
if (Prototype.S.startsWith(url,"mailto:")) {
var win = WindowUtils.getCurrentBrowserWindow(parent);
if (win) {
win.getBrowser().selectedBrowser.loadURI(url);
} else {
WindowUtils.newBrowserWindow(parent,url);
}
return "MAIL";
}
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserEnumerator = wm.getEnumerator("navigator:browser");
// Check each browser instance for our URL
var found = false;
while (!found && browserEnumerator.hasMoreElements()) {
var browserInstance = browserEnumerator.getNext().getBrowser();
// Check each tab of this browser instance
var numTabs = browserInstance.tabContainer.childNodes.length;
for ( var index = 0; index < numTabs; index++) {
var currentBrowser = browserInstance.getBrowserAtIndex(index);
if (url == currentBrowser.currentURI.spec) {
// The URL is already opened. Select this tab.
browserInstance.selectedTab = browserInstance.tabContainer.childNodes[index];
// Focus *this* browser
browserInstance.focus();
return "FOCUS_EXISTING";
}
}
}
// Our URL isn't open. Open it now.
switch (openMode) {
case 'current':
var win = WindowUtils.getCurrentBrowserWindow(parent);
if (win) {
win.getBrowser().selectedBrowser.loadURI(url);
return "CURRENT_TAB";
}
break;
case 'new-tab':
var win = WindowUtils.getCurrentBrowserWindow(parent);
if (win) {
var newTab = win.getBrowser().addTab(url);
win.getBrowser().selectedTab = newTab;
return "NEW_TAB";
}
break;
}
WindowUtils.newBrowserWindow(parent,url);
return "NEW_WINDOW";
},
}